<template>
  <div class='search'>
    <f-form ref='saleManform' :action='api.saleMan' :form-key='this.formItem.saleManId' handler-name='hyDeptSaleManSaveHandler'>
      <f-form-item label='姓名' name='saleManName' :value='formItem.saleManName' :required='true' />
      <f-form-item label='部门' ref='dept' type='select' name='deptId' :value.sync='formItem.deptId' :data='api.dept.list' valueKey='deptId' label-key='deptName' :params='queryParam' :required='true' />
      <f-form-item label='职务' type='select' name='positionId' :value='formItem.positionId' :data='api.position.list' valueKey='positionId' label-key='positionName' :required='true' />
      <f-form-item label='职务序号' name='positionOrder' :value='formItem.positionOrder' />
      <f-form-item label='招募人' placeholder='请选择招募人' name='parentName' @click='openSaleManModal' :readOnly='true'  :value.sync='formItem.parentName' :trigger-change='true' v-if='formItem.deptType=="ZY"'>
        <a-tooltip slot='addonBefore' placement='top' title='点击图标选择招募人'>
          <a-icon type='user' style='cursor:pointer' @click='openSaleManModal' />
        </a-tooltip>
      </f-form-item>
      <f-form-item label="省级" type='radio' name="proLevel" data-type="number"  :required='true' :data='api.busCommon.proLevel' :value="formItem.proLevel"/>
      <f-form-item label='身份证号' name='cardNo' :value='formItem.cardNo' />
      <f-form-item label='唯一编码' name='saleManCode' :value='formItem.saleManCode' />
      <f-form-item label='联系电话' name='linkTel' :value='formItem.linkTel' />
      <f-form-item label='备注' name='remark' :value='formItem.remark' />
    </f-form>
    <select-dept-man-modal ref='saleManModal' @onSelectChange='onSelectSaleManChange' :selectType='3' title='招募人选择'></select-dept-man-modal>
  </div>
</template>
<script>
import api from "../js/api"
import SelectDeptManModal from "@/views/module/haiying/components/select_deptman_modal"

export default {
  name: "salemanForm",
  props: {},
  watch: {
    "formItem.deptId"(newVal) {
      this.$nextTick(() => {
        this.$refs.saleMan.initData({
          deptId: newVal
        })
        //清除已选招募人
        this.$refs.saleManform.resetField("parentId")
      })
    }
  },
  data() {
    return {
      refs: this.$refs,
      areaIds: null,
      api: Object.assign(api, this.api),
      isAdd: true,//是否是添加模式
      autoLoad: false,
      loadSaleManParams: {
        saleManType: 1
      },
      queryParam: {
        isFlp: 1
      },
      loaded: false,//是否加载完成
      formItem: this.getFormItem()
    }
  },
  methods: {
    getFormItem() {
      return {
        saleManId: "",
        saleManName: "",
        cardNo: null,
        parentId: null,
        deptId: null,
        positionOrder: null,
        positionId: null,
        linkTel: "",
        amount: 0,
        reputation: 0,
        reputationAmount: 0,
        bankNo: "",
        remark: "",
        bankName: ""
      }
    },
    //表单赋值
    setData(data) {
      this.formItem = data
      if (data && data.saleManId) {
        let params = {
          saleManId: data.saleManId
        }
        this.refs["saleManform"].getDetails(params, (data) => {
          this.formItem = data
          this.areaIds = [this.formItem.proId, this.formItem.cityId, this.formItem.areaId]
          this.loaded = true
        })
        this.isAdd = false
      } else {
        this.formItem = this.getFormItem()
        this.areaIds = []
        this.loaded = true
      }
    },
    /**
     * 选择招募人
     */
    openSaleManModal() {
      this.$refs["saleManModal"].open({
        selectType: 3
      })
    },
    /**
     * 业务员选择回调
     */
    onSelectSaleManChange(selectedRowKeys, selectedRows) {
      this.$refs.saleManform.getForm().setFieldsValue({ "parentName": selectedRows[0].saleManName })
      this.formItem.parentName = selectedRows[0].parentName
      this.formItem.parentId = selectedRowKeys[0]
      this.$forceUpdate()
    },
    //提交表单
    handleSubmit(callback) {
      this.$refs.saleManform.submit({
        parentId: this.formItem.parentId,
        saleManType: 2,
        companyId: 5
      }, callback)
    }
  },
  created() {

  },
  components: { SelectDeptManModal }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
